//
//  SEGPersonalButtonView.m
//  ExcellentHome
//
//  Created by 刘山 on 16/11/16.
//  Copyright © 2016年 陈区. All rights reserved.
//

#import "SEGPersonalButtonView.h"

@implementation SEGPersonalButtonView

- (instancetype)initWithFrame:(CGRect)frame {
    if (self = [super initWithFrame:frame]) {
        [self setupUI];
    }
    return self;
}

- (void)setupUI
{
    [self addSubview:self.titleBtn];

    [self remakeConstraints];
}

- (void)remakeConstraints
{
    [self.titleBtn mas_remakeConstraints:^(MASConstraintMaker* make) {
        make.left.equalTo(self).mas_offset(15);
        make.right.equalTo(self).mas_offset(-15);
        make.height.mas_equalTo(44);
        make.centerY.equalTo(self);
    }];
}

- (void)setShowtype:(SEGButtonShowtype)showtype
{
    switch (showtype) {
    case SEGButtonShowtype_Center: {
        [self remakeConstraints];
    } break;
    default:
        [self remakeConstraints];
        break;
    }
}

- (UIButton*)titleBtn
{
    if (!_titleBtn) {
        _titleBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    }
    return _titleBtn;
}

- (void)setBackgroundColor:(UIColor *)backgroundColor {
    self.backgroundColor = backgroundColor;
    if (backgroundColor == kColor_T) {
        [self.titleBtn setBackgroundImage:[UIImage imageWithColor:kColor_T] forState:UIControlStateNormal];
        [self.titleBtn setBackgroundImage:[UIImage imageWithColor:kColor_T_Press] forState:UIControlStateHighlighted];
    } else {
        [self.titleBtn setBackgroundImage:nil forState:UIControlStateHighlighted];
    }
}

@end
